// 业务模块
#pragma once
// 完成计算任务
#include "Protocol.hpp"
#include <iostream>

class Cal
{
public:
    Response Execute(Request &req)
    {
        Response resp(0, 0);
        switch (req.Oper())
        {
        case '+':
            resp.Setresult(req.X()+req.Y());
            break;
        case '-':
            resp.Setresult(req.X()-req.Y());
            break;
        case '/':
            {
                if(req.Y()==0)
                {
                    resp.Setcode(1);//除0错误
                }
                else
                {
                    resp.Setresult(req.X()/req.Y());
                }
            }
            break;
        case '*':
            resp.Setresult(req.X()*req.Y());
            break;
        case '%':
            {
                if(req.Y()==0)
                {
                    resp.Setcode(2);//mod 0错误
                }
                else
                {
                    resp.Setresult(req.X()%req.Y());
                }
            }
            break;
        default:
            resp.Setcode(3);//非法操作
            break;
        }
        return resp;
    }
};